package com.fs.mapper;

import com.fs.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface UserMapper {

    /*用户登录*/
    @Select("select * from user where username = #{username}")
    User getByUsername(String username);

    /*用户注册*/
    @Insert("insert into user(username, password, sex, status, create_time, update_time)" +
            " VALUES (#{username},#{password},#{sex},#{status},#{createTime},#{updateTime})")
    Integer register(User user);

    /*根据用户ID查询用户信息*/
    @Select("select * from user where id = #{id}")
    User getById(Long id);

    /*编辑用户信息资料*/
    Integer update(User user);

    /*查询用户密码*/
    @Select("select user.password from user where id = #{userId}")
    String getPassword(Long userId);

    /*设置新密码*/
    @Update("update user set password=#{newpassword} where id = #{userId}")
    Integer reset(String newpassword, Long userId);
}
